// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let openid = wxContext.OPENID;
  let goods_id = event.goods_id;
  let myDate = new Date();
  let update_time = myDate.getTime();
  let update_time_show = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + myDate.getDate() + ' ' + myDate.getHours() + ':' + myDate.getMinutes() + ':' + myDate.getSeconds();
  try {
    return db.collection('ops_goods').where({
      _id: goods_id,
      Issuer_openid: openid
    }).update({
      data: {
        status: 0, // 已发货
        update_time: update_time,
        update_time_show: update_time_show
      }
    })
  } catch (e) {
    console.error(e)
  }
}